def  is1(n) :
    for i in range(2, int(n**0.5)+1 ) :
        if  n%i==0:
            return False
    return True

n=int(input())

n1=n//1000
n2=(n//100)%10
n3=(n//10)%10
n4=n%10

if  n<=1000 or n>=9999:
    print(0)
else:
    
    Max1=0
    
    if  is1(n) and Max1<n: Max1=n
    if  is1(n1) and Max1<n1: Max1=n1
    if  is1(n2) and Max1<n2: Max1=n2
    if  is1(n3) and Max1<n3: Max1=n3
    if  is1(n4) and Max1<n4: Max1=n4

    n12=n1*10+n2
    if  is1(n12) and Max1<n12: Max1=n12
    n13=n1*10+n3
    if  is1(n13) and Max1<n13: Max1=n13
    n14=n1*10+n4
    if  is1(n14) and Max1<n14: Max1=n14
    n23=n2*10+n3
    if  is1(n23) and Max1<n23: Max1=n23
    n24=n2*10+n4
    if  is1(n24) and Max1<n24: Max1=n24
    n34=n3*10+n4
    if  is1(n34) and Max1<n34: Max1=n34


    n123=n1*100+n2*10+n3
    if  is1(n123) and Max1<n123: Max1=n123
    n124=n1*100+n2*10+n4
    if  is1(n124) and Max1<n124: Max1=n124
    n234=n2*100+n3*10+n4
    if  is1(n234) and Max1<n234: Max1=n234


    print(Max1)
